<?php 

namespace Home\Controller;
use Think\Controller;
/**
* 登陆功能块
*/
class LoginController extends Controller
{
	
	public function index(){
		layout(false);
		if (IS_POST) {

			$username = I('post.user_name');
			$sql = "SELECT * from `user` WHERE `username` = '$username'";
			$user = M('user');
			$query = $user -> query($sql);

			if(md5(I('post.password'))==$query[0]['password']){
				//用户名
				$_SESSION['username']=$query[0]['username'];
				//用户id
				$_SESSION['id']=$query[0]['id'];
				//用户真实姓名
				$_SESSION['truename']=$query[0]['truename'];
				//性别
				$_SESSION['sex']=$query[0]['sex'];
				//分组
				$_SESSION['gid']=$query[0]['gid'];
				//生日
				$_SESSION['birthday']=$query[0]['birthday'];
				//工作
				$_SESSION['jobs']=$query[0]['jobs'];
				//介绍
				$_SESSION['introduce']=$query[0]['introduce'];
				//头像
				$_SESSION['head_img']=$query[0]['head_img'];
				//个性网站
				$_SESSION['web']=$query[0]['web'];
				//省
				$_SESSION['province']=$query[0]['province'];
				//市
				$_SESSION['city']=$query[0]['city'];
				//qq号
				$_SESSION['qq']=$query[0]['qq'];
				//电话号
				$_SESSION['phone']=$query[0]['phone'];
				//电子邮箱
				$_SESSION['email']=$query['email'];
				//个人网站
				$_SESSION['site']=$query[0]['site'];
				//积分
				$_SESSION['score']=$query[0]['score'];	
					
				if(I('post.net_auto_login')==1){

					cookie('username','$username',604800);//设置7天cookie
					cookie('password',I('post.password'),604800);

				}
				var_dump($_SESSION);
				
				$this->success('登陆成功！',U('Home/Setting/people'));
				return;
				

			}

			

			
		}
		$this->display();


	}
	public function check_ajax(){

		if (IS_POST) {
			
			$username = I('post.username');
			$user = M('user');
			$sql = "SELECT * FROM `user` WHERE `username` = '$username'";

			if(!$user->query($sql)){
				$data = 1;
				$this->ajaxReturn($data, 'json');
			}	
		}
	
	}

	public function loginout()
	{
		session_unset();
		session_destroy();
		
	}

}













 ?>